/*Class for input source code lines
	      1-8  Label
	       9  Blank
	    10-15 Operation code
	    16-17 Blank
	    18-35 Operand
	    36-66 Comment
*/

#include "headers.h"

struct linerec
   {
    char label[9];
    char opcode[7];
    char operand[19];
    int address;
   } line;

class srcline
{
 private:
    char label[9];
    char opcode[7];
    char operand[19];
    char address[4];
 public:
  srcline(char *s);
  int iscomm();
  char *makelength(char *s,int len);
};

srcline::srcline(char *s)
{
 int i;

 for(i=0;i<8;i++)
  *(label+i)=s[i];
 *(label+i)='\0';
 strcpy(label,makelength(label,8));

 for(i=9;i<15;i++)
  *(opcode+i-9)=s[i];
 *(opcode+i-9)='\0';
 strcpy(opcode,makelength(opcode,6));

 for(i=17;i<35;i++)
  {
   if(s[i]==',') break;
   *(operand+i-17)=s[i];
  }
 *(operand+i-17)='\0';
 strcpy(operand,makelength(operand,18));

 for(i=37;i<41;i++)
  *(address+i-37)=s[i];
 *(address+i-37)='\0';
 strcpy(address,makelength(address,4));

 strcpy(line.label,label);
 strcpy(line.opcode,opcode);
 strcpy(line.operand,operand);
 line.address=atoi(address);
}

int srcline::iscomm()
{
 if(label[0]=='.') return(1); else return(0);
}

char *srcline::makelength(char *s,int len)
{
 int i;
 if (strlen(s)<=len) for(i=strlen(s);i<len;i++) *(s+i)=' ';
 *(s+i)='\0';
 return(s);
}

/*
void main()
{
 char ts[]="TEST";
 srcline s(ts);
 getch();
}
*/